import java.util.Map;
import java.util.Scanner;


public class 摘花生 {
    static int N = 110;
    static int[][] arr = new int[N][N];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while(n-- >0) {
            //读入
            int row = scanner.nextInt();
            int col = scanner.nextInt();
            for (int i = 1; i <= row; i++)
                for (int j = 1; j <= col; j++)
                    arr[i][j] = scanner.nextInt();

            int max = 0;
            for(int i=1;i<=row;i++)
                for(int j=1;j<=col;j++){
                    arr[i][j] = Math.max(arr[i-1][j]+arr[i][j],arr[i][j-1]+arr[i][j]);
                }
           System.out.println(arr[row][col]);

        }
    }
}
